
module StrategyRunner
       ( evalOrder
       , evalOrders
       )
       where

import Types

evalOrders orders bar = foldl min (head barResults) barResults 
        where barResults =  map (evalOrder bar) orders

evalOrder bar order
        | ((orderPrice order) <= (barHigh bar) && (orderPrice order) >= (barLow bar)) = evalOrderOnBar order bar
        | otherwise  = 0.0

evalOrderOnBar (BuyOrder v price sl tp) bar 
        | price-sl >= (barLow bar)      = -sl*v
        | price+tp <= (barHigh bar)     = tp*v
        | otherwise                     = 0.0
        
        
evalOrderOnBar (SellOrder v price sl tp) bar
        | price+sl <= (barHigh bar)     = -sl*v
        | price-tp >= (barLow bar)      = tp*v
        | otherwise                     = 0.0    

